package com.ruoyi.order.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.order.domain.OrderCenter;
import com.ruoyi.order.service.OrderCenterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单中心控制器
 * 提供聚合展示商城订单和打印订单的接口
 */
@RestController
@RequestMapping("/api/order/center")
public class OrderCenterController extends BaseController {

    @Autowired
    private OrderCenterService orderCenterService;

    /**
     * 获取用户所有订单（商城+打印）
     */
    @GetMapping("/page")
    public TableDataInfo page(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        Long userId = getUserId();
        PageInfo<OrderCenter> page = orderCenterService.getUserAllOrders(userId, pageNum, pageSize);
        TableDataInfo rspData = getDataTable(page.getList());
        rspData.setTotal(page.getTotal());
        return rspData;
    }

    /**
     * 按状态筛选订单
     */
    @GetMapping("/page/status")
    public TableDataInfo pageByStatus(
            @RequestParam String status,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        Long userId = getUserId();
        PageInfo<OrderCenter> page = orderCenterService.getUserOrdersByStatus(userId, status, pageNum, pageSize);
        TableDataInfo rspData = getDataTable(page.getList());
        rspData.setTotal(page.getTotal());
        return rspData;
    }

    /**
     * 按类型筛选订单
     */
    @GetMapping("/page/type")
    public TableDataInfo pageByType(
            @RequestParam String orderType,
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "10") int pageSize) {
        Long userId = getUserId();
        PageInfo<OrderCenter> page = orderCenterService.getUserOrdersByType(userId, orderType, pageNum, pageSize);
        TableDataInfo rspData = getDataTable(page.getList());
        rspData.setTotal(page.getTotal());
        return rspData;
    }

    /**
     * 获取订单详情
     * 根据订单类型跳转到对应的详情接口
     */
    @GetMapping("/{id}/detail")
    public AjaxResult detail(@PathVariable Long id) {
        Long userId = getUserId();
        
        // 这里可以根据订单ID查询订单类型，然后返回对应的详情接口地址
        // 或者直接返回订单基本信息，让前端根据类型调用对应的详情接口
        
        return AjaxResult.success("请根据订单类型调用对应的详情接口");
    }
} 